package com.layui.ad.controller;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.layui.ad.constant.OperLogConstant;
import com.layui.ad.query.OperLogQuery;
import com.layui.ad.service.OperLogService;
import com.layui.ad.utils.JsonResult;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/operlog")
public class OperlogController {

    @Autowired
    private OperLogService operLogService;

    @GetMapping("/index")
    public String index(HttpServletRequest request){
        request.setAttribute("businessType", OperLogConstant.OPERLOG_BUSINESS_TYPE);
        request.setAttribute("status",OperLogConstant.OPERLOG_STATUS);
        return "operlog/index";
    }

    @PostMapping("/list")
    @ResponseBody
    @RequiresPermissions("operlog:list")
    public JsonResult list(OperLogQuery query){
        return operLogService.getList(query);
    }

    @GetMapping("/delete/{id}")
    @ResponseBody
    @RequiresPermissions("operlog:delete")
    public JsonResult delete(@PathVariable("id") Integer id){
        return operLogService.delete(id);
    }

    @ResponseBody
    @GetMapping("/batchDelete/{ids}")
    @RequiresPermissions("operlog:batchDelete")
    public JsonResult batchDelete(@PathVariable("ids") String ids){
        return operLogService.batchDelete(ids);
    }
}
